//
//  CrazyDragSecondViewController.m
//  CrazyDrag
//
//  Created by command.Zi on 14/11/25.
//  Copyright (c) 2014年 command.Zi. All rights reserved.
//

#import "CrazyDragSecondViewController.h"

@interface CrazyDragSecondViewController () {
    NSTimer *timer;
    BOOL ON;
    BOOL progressON;
}

- (IBAction)startprogress:(id)sender;
- (IBAction)stopView:(id)sender;
@property (strong, nonatomic) IBOutlet UIProgressView *progressView;


@end

@implementation CrazyDragSecondViewController
@synthesize progressView;


- (void)viewDidLoad {
    [super viewDidLoad];
    
    //滑动条循环开关
    ON = NO;
    //滑动条滑动开关
    progressON = YES;
    //启动滑动条
    [self startprogress];

    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)startprogress {
    if (progressON) {
        timer = [NSTimer scheduledTimerWithTimeInterval:0.009 target:self selector:@selector(changeProgress) userInfo:nil repeats:YES]; //利用计时器，每隔1秒调用一次（changeProgress)
    }else {
        [timer invalidate];
    }
}

- (void)changeProgress {
    if (ON == NO) {
        progressView.progress += 0.01;
        if (progressView.progress >= 1) {
            ON = YES;
        }
    }else if (ON == YES) {
        progressView.progress -= 0.01;
        if (progressView.progress == 0) {
            ON = NO;
        }
    }
}

-(void)startnewround {
    progressView.progress = 0;
    progressON = NO;
    [self startprogress];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)stopView:(id)sender {
    [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)startprogress:(id)sender {
    if (progressON) {
        progressON = NO;
    }else {
        progressON = YES;
    }
    [self startprogress];
    
    NSLog(@"%f",progressView.progress);
}

@end
